#include "department.h"

Department::Department(int m_id ,const char* str,int _total)
{
	total = _total;
	m_nld = m_id;
	strcpy(m_strName,str);
}

Department& Department::operator = (Department& that)
{
	if(this != & that)
	{
		total = that.total;
		m_nld = that.m_nld;
		strcpy(m_strName,that.m_strName);
	}

	return *this;
}

bool Department::deleteEmp(int _id)
{

	if(!m_vecEmps.size()) return false;

	vector<Employee*>::iterator itor;	
    for (itor = m_vecEmps.begin(); itor != m_vecEmps.end(); itor++)
    {
        if((*itor)->getId() == _id)
        {       
            itor = m_vecEmps.erase(itor);
            return true;
        }
       
	}
	return false;
}

bool Department::modifyEmp(Employee& employee)
{
	if(!m_vecEmps.size()) return false;

	vector<Employee*>::iterator itor;	
    for (itor = m_vecEmps.begin(); itor != m_vecEmps.end(); itor++)
    {
        if((*itor)->getId() == employee.getId())
        {       
            (*itor) = &employee;
            return true;
        }
       
	}
	return false;
}

void Department::listEmp(vector<Employee*>& employees)
{
	for(unsigned int i=0; i<m_vecEmps.size(); i++)
	{
		employees.push_back(m_vecEmps.at(i));
	}
}

vector<Employee*>& Department::get_employee_vector(void)
{
	return m_vecEmps;
}

int Department::getTotal()
{
	return total;
}

int Department::getDept_id(void)
{
	return m_nld;
}

const char* Department::getDept_name(void)
{
	return m_strName;
}

void Department::addTotal(void)
{
	total++;
}

void Department::subTotal(void)
{
	total--;
}

void Department::setID(int id)
{
	m_nld = id;
}

void Department::setTotal(int _total)
{
	total = _total;
}

void Department::setName(char * str)
{
	strcpy(m_strName,str);
}

Department::~Department(void)
{

}